$(function () {
    findName()
})


function findName() {
    let da={
        name:localStorage.getItem("username"),
    }
    let data=myAjax("/point/findByName",da,"post");
    data=data.list;
    let length=data.length;
    localStorage.setItem("length",length);
    let html='';
    for (let i=0;i<data.length;i++){
        html+='<tr>\n' +
            '                <td class="point-content" id="name'+i+'">'+data[i].name+'</td>\n' +
            '                <td  class="point-content">\n' +
            '                    <div>状态:\n' +
            '                        <label>已到<input type="radio" name="state'+i+'" value="已到" onclick="nodata('+i+')"></label>\n' +
            '                        <label>请假<input type="radio" name="state'+i+'" value="请假" onclick="nodata('+i+')"></label>\n' +
            '                        <label>迟到<input type="radio" name="state'+i+'" value="迟到" onclick="data('+i+')"></label>\n' +
            '                    </div>\n' +
            '                </td>\n'+
            '                <td  id="latedate'+i+'" class="point-content">\n' +
            '            </tr>';
    }
    $("#findName").html(html);
}

function data(i) {
    let html='<div>迟到时间: <input id="data'+i+'" type="datetime-local"></div>';
    $("#latedate"+i+"").html(html);
}

function nodata(i) {
    let html='';
    $("#latedate"+i+"").html(html);
}



function findTime() {
    let dat={
        name:$("#name"+0+"").text(),
    };
    let data=myAjax("/point/findTime",dat,"post");
    data=data.number;
    if (data==0){
        pointsubmit();
    }else {
        alert("今天已点到！");
        window.open('index.html','_self');
    }
}

function pointsubmit() {
    let length=localStorage.getItem("length")
    let data=[];
    for (let i=0;i<length;i++){
        let da={
            name:$("#name"+i+"").text(),
            state:$("input[name='state"+i+"']:checked").val(),
            arrive:$("#data"+i+"").val(),
        }
        data.push(da);
    }
    let dat=myAjax("/point/pointAdd",data,"post");
    dat=dat.result;
    if (dat==length){
        alert("提交成功！");
        $('#middle-reght').load('point/point.html');
    }else {
        alert("提交失败！")
    }
}



